package org.example.project_end.controller;

import lombok.extern.slf4j.Slf4j;
import org.example.project_end.entity.User;
import org.example.project_end.service.UserService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.http.ResponseEntity;
import org.springframework.web.bind.annotation.*;

@Slf4j
@CrossOrigin(origins = "http://localhost:5173")
@RestController
public class UserController {
    @Autowired
    UserService userService;
    @PostMapping("/api/login")
    public ResponseEntity<String> login(@RequestBody User user) {
        boolean success = userService.Login(user.getUsername(),user.getPassword());
        return success ? ResponseEntity.ok().body("登录成功") : ResponseEntity.notFound().build();
    }

    @PostMapping("api/register")
    public ResponseEntity<String> register(@RequestBody User user) {
        boolean success=userService.register(user.getUsername(),user.getPassword(),user.getPhone(),user.getEmail());
        return success ? ResponseEntity.ok("注册成功") : ResponseEntity.notFound().build();
    }
}
